 String.prototype.replaceAll = function(s1, s2) {
	return this.replace(new RegExp(s1, "gm"), s2);
}


 Date.prototype.pattern=function(fmt) {
	 var o = {
	 "M+" : this.getMonth()+1, //月份
	 "d+" : this.getDate(), //日
	 "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
	 "H+" : this.getHours(), //小时
	 "m+" : this.getMinutes(), //分
	 "s+" : this.getSeconds(), //秒
	 "q+" : Math.floor((this.getMonth()+3)/3), //季度
	 "S" : this.getMilliseconds() //毫秒
	 };
	 var week = {
	 "0" : "\u65e5",
	 "1" : "\u4e00",
	 "2" : "\u4e8c",
	 "3" : "\u4e09",
	 "4" : "\u56db",
	 "5" : "\u4e94",
	 "6" : "\u516d"
	 };
	 if(/(y+)/.test(fmt)){
	 fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	 }
	 if(/(E+)/.test(fmt)){
	 fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);
	 }
	 for(var k in o){
	 if(new RegExp("("+ k +")").test(fmt)){
	 fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
	 }
	 }
	 return fmt;
 } 

htmlToSpecchar=function(value){
	
	value=value.replaceAll("&lt;","<");
	value=value.replaceAll("&gt;",">");
  
	return   value;   
	
}
 

isEmpty =function(value) {  
    if (value!=undefined && value!=null && value!="")  
        return false;  
    else  
        return true;  
} 

/*判断是不是微信浏览器*/  
isweixin=function(){  
     var ua = navigator.userAgent.toLowerCase();  
     if(ua.match(/MicroMessenger/i)=="micromessenger") {  
         return true;  
     } else {  
         return false;  
     }  
 }  

isIE=function() { //ie?  
    if (!!window.ActiveXObject || "ActiveXObject" in window)  
        return true;  
    else  
        return false;  
} 

compaerDate=function(d1,d2){
	
	
	var date1=new Date(d1)
    var date2=new Date(d2)
 
	if(Date.parse(date1)>Date.parse(date2)){
		return 1;
	}else if(Date.parse(date1)==Date.parse(date2)){
		return 0;
	}else if(Date.parse(date1)<Date.parse(date2)){
		return -1;
	}
}


 
var Cookies = {};
/**//**
* 设置Cookies
*/
Cookies.setCookieVal = function(name, value){
	var argv = arguments;
	var argc = arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : '/';
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
};

 
Cookies.set =function(name,value,time){
	
	var strsec = getsec(time);
	var exp = new Date();
	exp.setTime(exp.getTime() + strsec*1);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();

};

getsec=function(str){
 
    var str1=str.substring(1,str.length)*1; 
    var str2=str.substring(0,1); 
    if (str2=="s"){
    return str1*1000;
    }else if (str2=="h"){
    return str1*60*60*1000;
    }else if (str2=="d"){
    return str1*24*60*60*1000;
    }
};

/**//**
* 读取Cookies
*/
Cookies.get = function(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	var j = 0;
	while(i < clen){
	j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	    return Cookies.getCookieVal(j);
	i = document.cookie.indexOf(" ", i) + 1;
	if(i == 0)
	    break;
	}
	return null;
};
/**//**
* 清除Cookies
*/
Cookies.clear = function(name) {
	if(Cookies.get(name)){
		var expdate = new Date(); 
		expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
		Cookies.set(name, "", expdate); 
     }
};

Cookies.getCookieVal = function(offset){
	var endstr = document.cookie.indexOf(";", offset);
	if(endstr == -1){
	   endstr = document.cookie.length;
	}
    return unescape(document.cookie.substring(offset, endstr));
};

//获取url中的参数
getUrlParamVal =  function(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

//url中将参数的值修改 
replaceParamVal =function (oldUrl, paramName, replaceWith) {
	
	if (oldUrl==null||oldUrl==""){
		return "";
	}
	
    var re = eval('/(' + paramName + '=)([^&]*)/gi');
    var nUrl = oldUrl.replace(re, paramName + '=' + replaceWith);
    return nUrl;
}

////删除url指定名称的参数
delParamVal=function(url ,name ){
 
	var str = "";

    if (url == null){
   	 return url;
   }
   	
    var arr = "";
    var returnurl = "";
    var setparam = "";
    if (str.indexOf('&') != -1) {
        arr = str.split('&');
        for (i in arr) {
            if (arr[i].split('=')[0] != name) {
                returnurl = returnurl + arr[i].split('=')[0] + "=" + arr[i].split('=')[1] + "&";
            }
        }
        return url.substr(0, url.indexOf('?')) + "?" + returnurl.substr(0, returnurl.length - 1);
    }
    else {
        arr = str.split('=');
        if (arr[0] == name)
            return url.substr(0, url.indexOf('?'));
        else
            return url;
    }

}

//将form中的值转换为键值对：
//如：{Name:'摘取天上星',position:'IT技术'}
//ps:注意将同名的放在一个数组里
getFormJson =function(form) {
	
	var o = {};
	var a = $(form).serializeArray();
	$.each(a, function () {
		if (o[this.name] !== undefined) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
}

//判断一个值或字符串在数组
in_array = function(search,array){
    for(var i in array){
        if(array[i]==search){
            return true;
        }
    }
    return false;
}

